/* eslint-disable */
'use strict';

const fs = require('fs');
module.exports = {
  base64_encode(file) {
    const newFile = fs.readFileSync(file);
    return newFile.toString('base64');
  },

  deleteFile(path) {
    return new Promise((resolve, rejects) => {
      fs.unlink(path, err => {
        if(err) {
          rejects(err);
        }
        resolve(path);
      })
    })
  },

  stat(path) {
    return new Promise((resolve, rejects) => {
      fs.stat(path, (err, stats) => {
        if(err) {
          rejects(err);
        }
        resolve(stats);
      })
    })
  },

  success({ ctx, res = null, msg = "请求成功" }) {
    ctx.body = {
      code: 0,
      msg,
      data: res,
    };
    ctx.status = 200;
  }
}